home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / music / ptsupp.lha / PT Support archive / Sources / CIAShell_OS.S < prev    next >
Text File  |  1996-01-30  |  5KB  |  198 lines

  1. ;------------------------------------------------------------------------------
  2. ;
  3. ;    $VER: CIA Shell OS v1.0 - by Håvard "Howard" Pedersen
  4. ;    © 1995-96 Mental Diseases
  5. ;
  6. ;    An OS-aware CIA-shell
  7. ;
  8. ;    I cannot be held responsible for any damage caused directly or in-
  9. ;    directly by this code. Still, every released version is thouroughly
  10. ;    tested with Mungwall and Enforcer, official Commodore debugging tools.
  11. ;    These programs traps writes to unallocated ram and reads/writes to/from
  12. ;    non-ram memory areas, which should cover most bugs.
  13. ;
  14. ;    HISTORY:
  15. ;
  16. ;v1.0    Initial release. Should work OK.
  17. ;
  18. ;------------------------------------------------------------------------------
  19. ;
  20. ;    PUBLIC FUNCTIONS:
  21. ;
  22. ;Function:    CIA_AddCIAInt()
  23. ;Purpose:    Attaches our interrupt to the CIA chip, trying both timers.
  24. ;        Returns 0 in D0 if something went wrong.
  25. ;
  26. ;Function:    CIA_RemCIAInt()
  27. ;Purpose:    Removes our CIA-interrupt.
  28. ;
  29. ;Function:    CIA_SetBPM(BPM)(D0.B)
  30. ;Purpose:    Adjusts the tempo of the current module.
  31. ;
  32. ;
  33. ;    EXTERNAL FUNCTIONS:
  34. ;
  35. ;Function:    CIA_CIAInt()
  36. ;Purpose:    Does any thingies that are necessary to perform within a CIA
  37. ;        interrupt. May trash only D0/D1/A0/A1.
  38. ;
  39. ;------------------------------------------------------------------------------
  40.  
  41. ; Constants. Feel free to change if you know what you're doing.
  42.  
  43. ; CIA interrupt definitions.
  44.  
  45. ciatalo = $400
  46. ciatahi = $500
  47. ciatblo = $600
  48. ciatbhi = $700
  49. ciacra  = $E00
  50. ciacrb  = $F00
  51.  
  52. ;------------------------------------------------------------------------------
  53. ;            C I A _ A D D C I A I N T
  54. ;------------------------------------------------------------------------------
  55. CIA_AddCIAInt    moveq.l    #2,d6
  56.         lea.l    $bfd000,a5
  57.         move.b    #'b',CIA_CIAName+3
  58. .SetCIALoop
  59.         moveq.l    #0,d0
  60.         lea.l    CIA_CIAName(pc),a1
  61.         move.l    4.w,a6
  62.         jsr    -498(a6)        ; _LVOOpenResource
  63.  
  64.         move.l    d0,CIA_CIABase
  65.         beq.w    .FatalError
  66.  
  67.         lea.l    CIA_GfxName(pc),a1
  68.         moveq.l    #0,d0
  69.         jsr    -552(a6)        ; _LVOOpenLibrary()
  70.  
  71.         tst.l    d0
  72.         beq.s    CIA_RemCIAInt
  73.  
  74.         move.l    d0,a1
  75.         move.w    206(a1),d0        ; Displayflags
  76.         btst    #2,d0            ; PAL?
  77.         beq.s    .WasNTSC
  78.  
  79.         move.l    #1773447,d7         ; PAL
  80.         bra.s    .GotTimer
  81.  
  82. .WasNTSC    move.l    #1789773,d7         ; NTSC
  83. .GotTimer    move.l    d7,CIA_TimerValue
  84.         divu    #125,d7         ; Default to normal 50 hz timer
  85.         jsr    -414(a6)        ; _LVOCloseLibrary()
  86.  
  87.         move.l    CIA_CIABase(pc),a6
  88.         cmp.w    #2,d6
  89.         beq.s    .TimerA
  90.  
  91. .TimerB        lea.l    CIA_MusIntServer(pc),a1
  92.         moveq.l    #1,d0            ; Bit 1: timer b
  93.         jsr    -6(a6)            ; _LVOAddICRVector()
  94.  
  95.         move.l    #1,CIA_TimerFlag
  96.         tst.l    d0
  97.         bne.s    .CIAError
  98.  
  99.         move.l    a5,CIA_CIAPtr
  100.         move.b    d7,ciatblo(a5)
  101.         lsr.w    #8,d7
  102.         move.b    d7,ciatbhi(a5)
  103.         bset    #0,ciacrb(a5)
  104.         moveq.l    #1,d0
  105.         rts
  106.  
  107. .TimerA        lea.l    CIA_MusIntServer(pc),a1
  108.         moveq.l    #0,d0            ; Bit 0: timer a
  109.         jsr    -6(a6)            ; _LVOAddICRVector()
  110.  
  111.         clr.l    CIA_TimerFlag
  112.         tst.l    d0
  113.         bne.s    .CIAError
  114.  
  115.         move.l    a5,CIA_CIAPtr
  116.         move.b    d7,ciatalo(a5)
  117.         lsr.w    #8,d7
  118.         move.b    d7,ciatahi(a5)
  119.         bset    #0,ciacra(a5)
  120.         moveq.l    #1,d0
  121.         rts
  122.  
  123. .CIAError    move.b    #'a',CIA_CIAName+3
  124.         lea.l    $bfe001,a5
  125.         subq.w    #1,d6
  126.         bne.s    .SetCIALoop
  127.  
  128.         clr.l    CIA_CIABase
  129. .FatalError    move.l    #0,d0
  130.         rts
  131.  
  132. ;------------------------------------------------------------------------------
  133. ;            C I A _ R E M C I A I N T
  134. ;------------------------------------------------------------------------------
  135. CIA_RemCIAInt    move.l    CIA_CIABase(pc),d0
  136.         beq.s    .Exit
  137.  
  138.         clr.l    CIA_CIABase
  139.         move.l    d0,a6
  140.         move.l    CIA_CIAPtr(pc),a5
  141.         tst.l    CIA_TimerFlag
  142.         beq.s    .TimerA
  143.  
  144.         bclr    #0,ciacrb(a5)
  145.         moveq.l    #1,d0
  146.         bra.s    .RemInt
  147.  
  148. .TimerA        bclr    #0,ciacra(a5)
  149.         moveq.l    #0,d0
  150. .RemInt        lea.l    CIA_MusIntServer(pc),a1
  151.         moveq.l    #0,d0
  152.         jsr    -12(a6)            ; _LVORemICRVector()
  153.  
  154. .Exit        rts
  155.  
  156. ;------------------------------------------------------------------------------
  157. ;            C I A _ S E T B P M
  158. ;------------------------------------------------------------------------------
  159. CIA_SetBPM    move.l    CIA_CIABase(pc),d1
  160.         beq.s    .Exit
  161.  
  162.         move.l    CIA_TimerValue(pc),d1
  163.         divu    d0,d1
  164.         move.l    CIA_CIAPtr(pc),a1
  165.         move.l    CIA_TimerFlag(pc),d0
  166.         beq.s    .TimerA
  167.  
  168. .TimerB        move.b    d1,ciatblo(a1)
  169.         lsr.w    #8,d1
  170.         move.b    d1,ciatbhi(a1)
  171.         rts
  172.  
  173. .TimerA        move.b    d1,ciatalo(a1)
  174.         lsr.w    #8,d1
  175.         move.b    d1,ciatahi(a1)
  176.  
  177. .Exit        rts
  178.  
  179. ;------------------------------------------------------------------------------
  180. ;            D A T A
  181. ;------------------------------------------------------------------------------
  182.  
  183. CIA_MusIntServer
  184.         dc.l    0,0
  185.         dc.b    2,5            ; Type, Priority
  186.         dc.l    .IntName
  187.         dc.l    0,CIA_CIAInt
  188.  
  189. .IntName    dc.b    "CIA Music interrupt",0
  190. CIA_CIAName    dc.b    "ciaa.resource",0
  191. CIA_GfxName    dc.b    "graphics.library",0
  192.     even
  193. CIA_CIAPtr    dc.l    0
  194. CIA_CIABase    dc.l    0
  195. CIA_TimerFlag    dc.l    0
  196. CIA_TimerValue    dc.l    0
  197.  
  198.